<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * Generator By "Code Generator Tools" At {_datetime_}
 */
class {_classname_} extends CI_Controller
{
	/**
	 * 数组，传递到Views试图中
	 */
	private $data;

	/**
	 * 分页中的每页显示的记录条数
	 */
	private $per_page = 10;

	public function __construct()
	{
		parent::__construct();

		$this->load->model('{_load_model_name_}');
	}

	public function index($page = 1)
	{
		if(!is_numeric($page) || $page < 1)
			$page = 1;

		$this->load->library('pagination');

		$config['base_url'] = config_item('base_url').'admin/{_controller_name_}/index/';
		$config['total_rows'] = $this->{_load_model_name_}->count_all();
		$config['uri_segment'] = 4;
		$config['num_links'] = 4;
		$config['use_page_numbers'] = TRUE;
		$config['per_page'] = $this->per_page;
		$config['first_link'] = '第一页';
		$config['next_link'] = '下一页';
		$config['prev_link'] = '上一页';
		$config['last_link'] = '最后一页';
		$this->pagination->initialize($config);
		$this->data['pagination'] = $this->pagination->create_links();

		$limit = $this->per_page;
		$offset = ($page - 1) * $limit;
		$this->data['list'] = $this->{_load_model_name_}->get_list($limit, $offset);

		$this->load->view('{_index_view_file_}', $this->data);
	}

	// /admin/{_controller_name_}/search/field_name,keywords/1
	public function search($content, $page = 1)
	{
		if(empty($content)) return;

		$search_types = explode(',', $content);
		if(empty($search_types) || count($search_types) != 2) return;

		$search_field = $search_types[0];
		$search_keywords = $search_types[1];
		$limit = $this->per_page;
		$offset = ($page - 1) * $limit;

		$this->load->library('pagination');

		$config['base_url'] = config_item('base_url').'admin/{_controller_name_}/search/'.$content.'/';
		$config['total_rows'] = $this->{_load_model_name_}->count_search($search_field, $search_keywords);
		$config['uri_segment'] = 5;
		$config['num_links'] = 4;
		$config['use_page_numbers'] = TRUE;
		$config['per_page'] = $this->per_page;
		$config['first_link'] = '第一页';
		$config['next_link'] = '下一页';
		$config['prev_link'] = '上一页';
		$config['last_link'] = '最后一页';
		$this->pagination->initialize($config);
		$this->data['pagination'] = $this->pagination->create_links();

		$this->data['search_list'] =  $this->{_load_model_name_}->search($search_field, $search_keywords, $limit, $offset);

		//$this->load->view('{_search_view_file_}', $this->data);
	}

	public function detail({_primary_key_params_})
	{
		{empty_check(_primary_key_params_)}

		$this->data['detail'] = $this->{_load_model_name_}->get({_primary_key_params_});
		$this->load->view('{_detail_view_file_}', $this->data);
	}

	public function add()
	{
	}

	public function edit({_primary_key_params_})
	{
		{empty_check(_primary_key_params_)}

	}
	
	public function delete({_primary_key_params_})
	{
		{empty_check(_primary_key_params_)}
	}
}